#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "autologin.h"

int main(int argc, char *argv[]) {
	char *login; //intitialise the pointer for login name
	char *ttyd; //initialise the pointer for tty
	int index;
	int testflag;

	for (index = optind; index < argc; index++){
		login = argv[index];
	} //put into login the login and into ttyd the tty
	while ((testflag = getopt (argc, argv, "curh")) != -1) {
		switch (testflag){
			case 'c':
				configure (login);
			break;
			case 'u':
				usagelogin (login);
			break;
			case 'r':
				removeautologin (login);
			break;
			case 'h':
				help();
			break;
			case '?':
				if (isprint (optopt))
					fprintf (stderr, "Unknow option `-%c'.\nFor help type 'autologin -h'\n", optopt);
				else
					fprintf (stderr, "Unknow option character `\\x%x'.\n", optopt);
				return 1;
			default:
				abort ();
			break;
			}//test the flag command
	}



	return 0;
}

int usagelogin (char *loginname) {
	execlp("login","login","-f", loginname, 0);
	//login use for script
	return 0;
}

int help (void) {
	printf("autologin v0.1:\n usage: autologin [-curh] login_name ttyconsole\n\n	-c configure autologin\n	-u usage for autologin\n	-r remove a autologin user\n	-h show this help\n");
	//help
	return 0;
}

int configure (char *loginname, char *ttyconsole) {
	//this will futhermore configure the init.d and the ttys
	return 0;
}

int removeautologin (char *loginname, char *ttyconsole) {
	//remove the autologin user
	return 0;
}
